/**
 * 全站路由配置
 *
 * meta参数说明
 * keepAlive是否缓冲页面
 * isTab是否加入到tag导航
 * isAuth是否需要授权
 */
import VueRouter from 'vue-router';
import PageRouter from './page/'
import ViewsRouter from './views/'
import AvueRouter from './avue-router';
import Vue from 'vue';
import i18n from '@/lang' // Internationalization
import Store from '../store/';

let Router = new VueRouter({
    scrollBehavior(to, from, savedPosition) {
      //    console.log("to",to)
      // console.log("from",from)
      // console.log("savedPosition",savedPosition)
      // var strings=[
      //   { path:null,
      //     name:null
      //   },
      //   { path:null,
      //     name:null
      //   }
      // ]
      //   if(to.matched.length==0){
      //     var strings2 = to.path.split("/");
      //     console.log("strings2",strings2)
      //     if(strings2.length>1){
      //       strings[0].path="/"+strings2[1]
      //       strings[1].path = to.path
      //       strings[1].name = to.name
      //        to.matched[0]=cloneObj(strings[0])
      //       to.matched[1]=cloneObj(strings[1])
      //     }
      //   }
      //
      // console.log("strings",to.matched)
        if (savedPosition) {
            return savedPosition
        } else {
            if (from.meta.keepAlive) {
              console.log("from.meta.keepAlive",from.meta.keepAlive)
                from.meta.savedPosition = document.body.scrollTop;
            }
          console.log("to.meta.savedPosition",to.meta.savedPosition)
            return {
                x: 0,
                y: to.meta.savedPosition || 0
            }
        }
    },
    routes: []
});
AvueRouter.install(Vue, Router, Store, i18n);
Router.$avueRouter.formatRoutes(Store.state.user.menu, true);
Router.addRoutes([...PageRouter, ...ViewsRouter]);
export default Router;
